<?php
/**
 * 默认控制器
 * 
 * @version $Id: Site.php 317 2012-05-17 09:11:37Z linsir123 $
 */
class controllerSite extends AppController 
{
	/**
	 * 默认的控制器名称
	 */
	public $defaultAction = 'home';
	
	/**
	 * 首页
	 */
	public function actionHome()
	{
		if ($this->checkCache('home')) 
			return ;
			
		///
		View::assignSet(array(
			'arts' => file_get_contents("http://www.e35go.com/__wordpress/index-posts.php"),
			'taobaokes' => M::item()->getHomeList(),
			'shops' => App::O('_home.shop'),
			'dh' => $this->_homeClass(1),
		));
	}
	
	/**
	 * FAQ
	 */
	public function actionFaq()
	{
		$m = M::faq();
		$type = intval($_GET['type']);
		$list = $m->getList($type);
		
		///
		View::display('faq');
		View::assignSet(array(
			'type' => $type,
			'types' => $m->types,
			'list' => $list
		));
	}
	
	/**
	 * 搜索
	 */
	public function actionSearch()
	{
		if (Request::isPost()) {
			$k = trim($_POST['k']);
			if (strpos($k, "http")===0) {
				$tmp = parse_url($k);
				parse_str($tmp['query'], $tmp);
				if (isset($tmp['id'])) {
					$item = M::item()->getTaobaoke($tmp['id']);
					if ( ! empty($item)) 
						$k = strip_tags($item['title']);
				}
			}
			
			$params = array(
				'pinyin'=>'search',
				'keyword'=>$k,
			);
			$url = AppView::urlClass($params);
			lpUrl::redirect($url);
		} else {
			if ($this->checkCache('search')) 
				return ;
				
			///
			AppView::addCss('themes/default/search.css');
		}
	}
	
	/**
	 * 404
	 */
	public function actionMiss()
	{
		lpUrl::_r();
	}
	
	
	/// 以下为私有方法 ///
	
	
	/**
	 * 首页导航
	 */
	private function _homeClass($type = 0)
	{
		/* 春夏 */
		if ($type == 1) 
			return App::O('_homeClass2');
			
		/* 秋冬 */
		$dh = App::O('_homeClass');
		foreach ($dh as $i => $v) {
			$data = array();
			foreach ($v['list'] as $t => $name) {
				if (is_int($t)) 
					$data[] = array($name, $t, $t, '');
				else {
					$t = explode('_', $t);
					$data[] = array($name, $t[0], $t[0].'_'.$t[1], $t[2]);
				}
			}
			
			// 分类名称,分类ID,分类图片名,关键字
			$v['list'] = $data;
			$dh[$i] = $v;
		}
		
		return $dh;
	}
}
